package com.chaoyong.higo.activity;

import java.io.UnsupportedEncodingException;

import org.apache.http.entity.StringEntity;
import org.json.JSONException;
import org.json.JSONObject;

import com.chaoyong.higo.R;
import com.chaoyong.higo.adapter.AccountSafeAdapter;
import com.chaoyong.higo.base.BaseActivity;
import com.chaoyong.higo.net.OApi;
import com.chaoyong.higo.utils.PrefUtils;
import com.chaoyong.higo.utils.V;
import com.chaoyong.higo.utils.Values;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.tw.wheel.popwin.AreaPickPopWin.Builder;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class AccountSafeActivity extends BaseActivity implements OnItemClickListener {

	private LinearLayout base_left_iv;// 左侧返回按钮
	private TextView base_title_tv;// 标题
	private TextView base_right_tv;// 标题右侧文字

	private ListView safe_list_view;
	private AccountSafeAdapter adapter;

	private Button adress_add_new_btn;

	@Override
	public int layoutResID() {
		return R.layout.activity_account_safe;
	}

	@Override
	public void findView() {
		findTitleIds();
	}

	private void findTitleIds() {
		base_left_iv = V.f(this, R.id.base_left_iv);
		base_title_tv = V.f(this, R.id.base_title_tv);
		base_right_tv = V.f(this, R.id.base_right_tv);

		adress_add_new_btn = V.f(this, R.id.adress_add_new_btn);
		adress_add_new_btn.setVisibility(View.GONE);
		base_title_tv.setText("账户安全");
		base_right_tv.setVisibility(View.GONE);
	}
	

	@Override
	public void init() {
		base_left_iv.setOnClickListener(this);

		safe_list_view = V.f(this, R.id.safe_list_view);
		adapter = new AccountSafeAdapter(this);

		safe_list_view.setOnItemClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.base_left_iv:// title左侧返回
			this.finish();
			break;
		}
	}

	@Override
	protected void onStart() {
		super.onStart();
		safe_list_view.setAdapter(adapter);
		//getPhone();
		
	}

	/*private void getPhone() {
		// TODO Auto-generated method stub
		JSONObject info = new JSONObject();
		try {
			info.put("uid", PrefUtils.getString(this, "userId", ""));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JSONObject json = new JSONObject();
		try {
			json.put("model", "MemberInfo");
			json.put("function", "index");
			json.put("info", info);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		RequestParams params = new RequestParams();
		try {
			params.setBodyEntity(new StringEntity(json.toString(), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HttpUtils utils = new HttpUtils();
		utils.send(HttpMethod.POST, Values.BASE_URL + OApi.Appport_appMember, params, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}*/

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		switch (arg2) {
		case 0:
			// showToast("登录密码");
			startActivity(new Intent(this, NotifyPwdActivity.class));
			break;
		case 2:
			// showToast("手机号");
			startActivity(new Intent(this, NotifyTelnumberActivity.class));
			break;
		case 1:
			startActivity(new Intent(this, ModifyPayPwd01Activity.class));
			break;
		case 4:
			// showToast("邮箱");
			startActivity(new Intent(this, NotifyEmailActivity.class));
			break;
		}
	}

}
